<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="用户id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId">
              <a-input v-model="model.userId" placeholder="请输入用户id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户昵称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userName">
              <a-input v-model="model.userName" placeholder="请输入用户昵称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="提现方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payType">
              <j-dict-select-tag type="list" v-model="model.payType" dictCode="pay_type" placeholder="请选择提现方式" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="提现用户名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="realName">
              <a-input v-model="model.realName" placeholder="请输入提现用户名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="提现账户(银行卡卡号)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="account">
              <a-input v-model="model.account" placeholder="请输入提现账户(银行卡卡号)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="银行名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankName">
              <a-input v-model="model.bankName" placeholder="请输入银行名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="提现金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="withdrawalAmount">
              <a-input v-model="model.withdrawalAmount" placeholder="请输入提现金额"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="兑换钻石" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="diamondNum">
              <a-input v-model="model.diamondNum" placeholder="请输入兑换钻石"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="到账金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receivedAmount">
              <a-input v-model="model.receivedAmount" placeholder="请输入到账金额(元)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="手续费(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="commission">
              <a-input v-model="model.commission" placeholder="请输入手续费(元)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="提现手续费(%)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="withdrawalRate">
              <a-input v-model="model.withdrawalRate" placeholder="请输入提现手续费(%)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="提现状态(1-待审核  2-待打款 3-打款成功 4-提现失败)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <j-dict-select-tag type="list" v-model="model.status" dictCode="withdrawal_status" placeholder="请选择提现状态(1-待审核  2-待打款 3-打款成功 4-提现失败)" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审核时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditTime">
              <j-date placeholder="请选择审核时间"  v-model="model.auditTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="提现描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="withdrawalDetail">
              <a-input v-model="model.withdrawalDetail" placeholder="请输入提现描述"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="打款时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentTime">
              <j-date placeholder="请选择打款时间"  v-model="model.paymentTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'WithdrawalForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/user.withdrawal/withdrawal/add",
          edit: "/user.withdrawal/withdrawal/edit",
          queryById: "/user.withdrawal/withdrawal/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>